import { Ref, ref } from "vue"

const statusBarRef = ref()// statusBar ---------- 状态栏高度
const customBarRef = ref()// customBar -------- 状态栏高度 + 导航栏高度
const navBarRef = ref()
const isIphoneAdaptationRef = ref()
const titleHeightRef = ref()
type returnType= {
	statusBarRef: Ref, customBarRef: Ref, navBarRef: Ref, isIphoneAdaptationRef: Ref, titleHeightRef: Ref
}
export const useSystemInfo = (): returnType => {

	// 下面这个方法可以获取状态栏高度和导航栏高度以及机型
	uni.getSystemInfo({
		success: (e) => {
			let statusBar:number|undefined = 0
			let navBar:number|undefined = 0
			let customBar:number|undefined = 0


			// #ifdef MP
			statusBar = e.statusBarHeight
			customBar = e .statusBarHeight as number + 45
			if (e.platform === 'android') {
				customBar = e.statusBarHeight as number + 50
			}
			// #endif


			// #ifdef MP-WEIXIN
			statusBar = e.statusBarHeight
			// @ts-ignore
			const custom = wx.getMenuButtonBoundingClientRect()
			customBar = custom.bottom + custom.top -( e.statusBarHeight ||0)
			// #endif


			// #ifdef MP-ALIPAY
			statusBar = e.statusBarHeight
			customBar = e.statusBarHeight as number + (e.titleBarHeight ||0 )
			// #endif


			// #ifdef APP-PLUS
			console.log('app-plus', e)
			statusBar = e.statusBarHeight
			customBar = e.statusBarHeight as number + 45
			// #endif


			// #ifdef H5
			statusBar = 0
			customBar = e.statusBarHeight as number + 45
			// #endif

			navBar = customBar - statusBar
			statusBarRef.value = statusBar
			customBarRef.value = customBar
			navBarRef.value = navBar

			if ((e.model.search('iPhone X') !== -1 || e.model.search('iPhone 11') !== -1 || e.model.search('iPhone 12')) != -1) {
				isIphoneAdaptationRef.value = true
				if (isIphoneAdaptationRef.value) {
					titleHeightRef.value = 170
				}
			}
		}
	})

	return { statusBarRef, customBarRef, navBarRef, isIphoneAdaptationRef, titleHeightRef }
}
 